﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Kingdom_of_the_Dragon
{
    class Dragon : LiveObject
    {
        
        private bool     voando = true;
              
        public Dragon(Texture2D texDragon, Vector2 posDragon, int speed)
        {
            this.position = posDragon;
            this.texture = texDragon;
            this.speed = 5;            
        }
        public Dragon()
        {
        }

        
        
        public void Move(KeyboardState kAtual, KeyboardState kPrevious, Keys cima, Keys baixo, Keys esquerda, Keys direita)
        {
            radians_direct = MathHelper.ToRadians(angle_direct);

            if (kAtual.IsKeyDown(cima))
            {
                if (speed < 100 && olhandoDireita)
                { speed++; }
                else if (!olhandoDireita && speed > -100)
                { speed--; }
                //if (olhandoDireita)
                //{                    
                    position += new Vector2(((float)Math.Cos(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))) * (speed / 10)), ((float)Math.Sin(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90)))) * (speed / 10));
                //}
                //else
                //{
                //    //position += new Vector2(((float)Math.Cos(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))) * (speed / 10)), ((float)Math.Sin(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90)))) * (speed / 10));
                //}
                
            }
            else if (kAtual.IsKeyUp(cima))
            {
                if (speed <= 100 && speed > 0)
                {
                    speed--;
                    position += new Vector2(((float)Math.Cos(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))) * (speed / 10)), ((float)Math.Sin(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90)))) * (speed / 10));
                }
                if (speed >= -100 && speed < 0)
                {
                    speed++;
                    position += new Vector2(((float)Math.Cos(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))) * (speed / 10)), ((float)Math.Sin(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90)))) * (speed / 10));
                }
            }
            if (kAtual.IsKeyDown(baixo) && kPrevious.IsKeyUp(baixo))
            {
                if (olhandoDireita)
                {
                    olhandoDireita = false;
                    //if (speed < 0)
                    //{
                    //    speed *= -1;
                    //}
                    //else
                    //{ }
                    
                    //angle_direct -= 180;
                }
                else
                {
                    olhandoDireita = true;
                    //if (speed > 0)
                    //{
                    //    speed *= -1;
                    //}
                    //else
                    //{ }
                //angle_direct += 180;
                }
                //position -= new Vector2((float)Math.Cos(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))), (float)Math.Sin(Convert.ToDouble(MathHelper.ToRadians(angle_direct - 90))));
            }
            if (kAtual.IsKeyDown(esquerda))
            {
                angle_direct -= 2;
            }
            if (kAtual.IsKeyDown(direita))
            {
                angle_direct += 2;
            }
            if (!voando)
            {
                position.Y += gravity;
            }
        }


        public bool OlhandoDireita
        {
            get { return olhandoDireita; }
            set { olhandoDireita = value; }
        }    
    }
}
